
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 17/11/2013 20:29:50
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class Product
    /// </summary>
    [Serializable]
    public partial class Product : _DomainLayer_Base  
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual int Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_VAT.
        /// </summary>
        /// <value>The FK_VAT.</value>
        /// <remarks>
        /// Foregn key of Product
        /// 
        /// </remarks>
        public virtual int FK_VAT
        {
            get { return _fK_VAT; }
            set
            {
                if (_fK_VAT != value)
                {
                    if (VAT != null && VAT.Id != value)
                    {
                        VAT = null;
                    }
                    _fK_VAT = value;
                }
            }
        }
        private int _fK_VAT;
    	
        /// <summary>
        /// Gets or sets Name.
        /// </summary>
        /// <value>The Name.</value>
        public virtual string Name
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets Description.
        /// </summary>
        /// <value>The Description.</value>
        public virtual string Description
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets UnitPrice.
        /// </summary>
        /// <value>The UnitPrice.</value>
        public virtual decimal UnitPrice
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets Picture.
        /// </summary>
        /// <value>The Picture.</value>
        public virtual string Picture
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion

        #region Navigation Properties
    
        /// <summary>
        /// Link Product to all OrderDetail
        /// </summary>
        public virtual ICollection<OrderDetail> OrderDetail
        {
            get
            {
                if (_orderDetail == null)
                {
                    var newCollection = new FixupCollection<OrderDetail>();
                    newCollection.CollectionChanged += FixupOrderDetail;
                    _orderDetail = newCollection;
                }
                return _orderDetail;
            }
            set
            {
                if (!ReferenceEquals(_orderDetail, value))
                {
                    var previousValue = _orderDetail as FixupCollection<OrderDetail>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupOrderDetail;
                    }
                    _orderDetail = value;
                    var newValue = value as FixupCollection<OrderDetail>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupOrderDetail;
                    }
                }
            }
        }
        private ICollection<OrderDetail> _orderDetail;
        public virtual VAT VAT
        {
            get { return _vAT; }
            set
            {
                if (!ReferenceEquals(_vAT, value))
                {
                    var previousValue = _vAT;
                    _vAT = value;
                    FixupVAT(previousValue);
                }
            }
        }
        private VAT _vAT;

        #endregion

        #region Association Fixup
    
        private void FixupVAT(VAT previousValue)
        {
            if (previousValue != null && previousValue.Product.Contains(this))
            {
                previousValue.Product.Remove(this);
            }
    
            if (VAT != null)
            {
                if (!VAT.Product.Contains(this))
                {
                    VAT.Product.Add(this);
                }
                if (FK_VAT != VAT.Id)
                {
                    FK_VAT = VAT.Id;
                }
            }
        }
    
        private void FixupOrderDetail(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (OrderDetail item in e.NewItems)
                {
                    item.Product = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (OrderDetail item in e.OldItems)
                {
                    if (ReferenceEquals(item.Product, this))
                    {
                        item.Product = null;
                    }
                }
            }
        }

        #endregion

    }
}
